/**
 * 
 */
package com.alstudio.view.absadapter;

import java.util.ArrayList;

import com.alstudio.app.ALLocalEnv;
import com.alstudio.module.xmpp.protocol.xmpp.data.economic.EconomicRecords;
import com.loovee.imaohu.R;

import android.text.format.DateUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * @author Administrator
 *
 */
public class ConsumptionAdapter extends ViewAdapter {
	private ArrayList<EconomicRecords> records;
	
	public ConsumptionAdapter(ArrayList<EconomicRecords> records){
		this.records = records;
	}

	/* (non-Javadoc)
	 * @see com.alstudio.view.absadapter.ViewAdapter#getRealCount()
	 */
	@Override
	public int getRealCount() {
		// TODO Auto-generated method stub
		return records.size();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return records.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return records.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if(convertView == null){
			viewHolder = new ViewHolder();
			convertView = ALLocalEnv.getLocalEnv().getGlobalLayoutInflater().inflate(R.layout.consumption_records_item, null);
			viewHolder.datetime_layout = (RelativeLayout) convertView.findViewById(R.id.datetime_layout);
			viewHolder.view_action_info = (TextView) convertView.findViewById(R.id.view_action_info);
			viewHolder.view_consume_info = (TextView) convertView.findViewById(R.id.view_consume_info);
			viewHolder.view_datetime = (TextView) convertView.findViewById(R.id.view_datetime);
			
			convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		
		viewHolder.datetime_layout.setVisibility(View.GONE);
		
		EconomicRecords item = records.get(position);
		
		if(item.getDate() != 0){
			viewHolder.datetime_layout.setVisibility(View.VISIBLE);
			viewHolder.view_datetime.setText(DateUtils.formatDateTime(ALLocalEnv.getLocalEnv().getContext(), item.getDate() * 1000, 0));
		}
		
		viewHolder.view_action_info.setText(item.getDesc());
		viewHolder.view_consume_info.setText(item.getGold());
		return convertView;
	}
	
	class ViewHolder{
		public RelativeLayout datetime_layout;
		public TextView view_action_info;
		public TextView view_consume_info;
		public TextView view_datetime;
	}

}
